package com.chlitina.store.modules.cash.model;

import java.util.ArrayList;
import java.util.List;

import com.chlitina.store.modules.base.entity.StoreProduct;
import com.chlitina.store.modules.expert.entity.CustomerExam;


public class MemberShoppingCart extends ShoppingCart {
	private CustomerExam customerExam;
	Member member = null;
	public MemberShoppingCart(Member member) {
		this.member = member;
	}
	private List<SolutionStoreProductCart> solutionProducts=new ArrayList<SolutionStoreProductCart>();
	private List<SolutionStoreCareCart> solutionCares=new ArrayList<SolutionStoreCareCart>();
	
	private List<StoreProductCart> systemProducts = new ArrayList<StoreProductCart>();
	private List<StoreProductCart> storeProducts = new ArrayList<StoreProductCart>();
	public List<StoreProductCart> getSystemProducts() {
		return systemProducts;
	}
	 
	public void setSystemProducts(List<StoreProductCart> systemProducts) {
		this.systemProducts = systemProducts;
	}

	public List<StoreProductCart> getStoreProducts() {
		return storeProducts;
	}

	public void setStoreProducts(List<StoreProductCart> storeProducts) {
		this.storeProducts = storeProducts;
	}
	public void deleteSystemProduct(int id) {
		removeProduct(systemProducts, id);
	}

	public void deleteStoreProduct(int id) {
		removeProduct(storeProducts, id);
	}
	
	@Override
	protected boolean isForMemeber() {
		return true;
	}
	
	private int carecartid = 0;

	public void generateCareCartId(StoreCareCart storeCareCart) {
		if (storeCareCart.getId() == 0) {
			carecartid++;
			storeCareCart.setId(carecartid);
		}
	}

	public void calculatePayment(){
		for (StoreProductCart cart : getStoreProducts()) {
			calculatePayment(cart);
		}
		for (StoreProductCart cart : getSystemProducts()) {
			calculatePayment(cart);
		}
		for (StoreProductCart cart : getSolutionProducts()) {
			calculatePayment(cart);
		}
		for (StoreCareCart cart : getStoreCares()) {
			calculatePayment(cart);
		}
		for (StoreCareCart cart : getSystemCares()) {
			calculatePayment(cart);
		}
		for (StoreCareCart cart : getSolutionCares()) {
			calculatePayment(cart);
		}
	}
	
	
	private void calculatePayment(StoreProductCart cart) {
		member.updateAvailableAllCards();
		member.updateAvailableProductCards();
		
		cart.calculatePayment(member);
		cart.updateDetails();
		System.err.println(cart.getDetails());
	}

	private void calculatePayment(StoreCareCart cart) {
		member.updateAvailableAllCards();
		member.updateAvailableDurationCards();
		member.updateAvailableTimesCards();
		
		cart.calculatePayment(member);
		cart.updateDetails();
		System.err.println(cart.getPayment().getDescription());
	}
	
	
	public void buyProducts(StoreProductCart product) {
		if(product.getStoreProduct().getProduct_type()==StoreProduct.TYPE_SELF){
			getStoreProducts().add(product);
		}else{
			getSystemProducts().add(product);
		}
		member.updateMenuState();
	}
	
	public void buySystemProducts(StoreProductCart product) {
		getSystemProducts().add(product);
		member.updateMenuState();
	}


	public void buyStoreProducts(StoreProductCart product) {
		getStoreProducts().add(product);
		member.updateMenuState();
	}
	
	public void addSolutionStoreProduct(
			SolutionStoreProductCart storeProductCart) {
		getSolutionProducts().add(storeProductCart);
		member.updateMenuState();
	}
	public void addSolutionStoreCare(
			SolutionStoreCareCart storeCareCart) {
		getSolutionCares().add(storeCareCart);
		member.updateMenuState();
	}
	public void doSystemCare(StoreCareCart care) {
		generateCareCartId(care);
		getSystemCares().add(care);
		member.updateMenuState();
	}

	public List<SolutionStoreProductCart> getSolutionProducts() {
		return solutionProducts;
	}


	public List<SolutionStoreCareCart> getSolutionCares() {
		return solutionCares;
	}

	public CustomerExam getCustomerExam() {
		return customerExam;
	}

	public void setCustomerExam(CustomerExam customerExam) {
		this.customerExam = customerExam;
	}


}
